home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / ODF Release 3 / ODFDev / Draw / Sources / DrawFrm.cpp < prev    next >
Encoding:
Text File  |  1996-12-16  |  26.9 KB  |  934 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                DrawFrm.cpp
  4. //    Release Version:    $ ODF 3 $
  5. //
  6. //    Author:                Henri Lamiraux
  7. //
  8. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #include "ODFDraw.hpp"
  13.  
  14. #ifndef DRAWFRM_H
  15. #include "DrawFrm.h"
  16. #endif
  17.  
  18. #ifndef DEFINES_K
  19. #include "Defines.k"
  20. #endif
  21.  
  22. #ifndef DRAWPART_H
  23. #include "DrawPart.h"
  24. #endif
  25.  
  26. #ifndef DRAWVIEW_H
  27. #include "DrawView.h"
  28. #endif
  29.  
  30. #ifndef CLIPCMDS_H
  31. #include "ClipCmds.h"
  32. #endif
  33.  
  34. #ifndef DRAWSEL_H
  35. #include "DrawSel.h"
  36. #endif
  37.  
  38. #ifndef INSRTCMD_H
  39. #include "InsrtCmd.h"
  40. #endif
  41.  
  42. #ifndef CONTENT_H
  43. #include "Content.h"
  44. #endif
  45.  
  46. #ifndef DRAWPRXY_H
  47. #include "DrawPrxy.h"
  48. #endif
  49.  
  50. #ifndef SHPTRAKR_H
  51. #include "ShpTrakr.h"
  52. #endif
  53.  
  54. #ifndef DRAWCMDS_H
  55. #include "DrawCmds.h"
  56. #endif
  57.  
  58. #ifndef DRAWCLIP_H
  59. #include "DrawClip.h"
  60. #endif
  61.  
  62. #ifndef UTILS_H
  63. #include "Utils.h"
  64. #endif
  65.  
  66. #ifndef DRWDDCMD_H
  67. #include "DrwDDCmd.h"
  68. #endif
  69.  
  70. #ifndef RULER_H
  71. #include "Ruler.h"
  72. #endif
  73.  
  74. #ifndef DRAWCONT_H
  75. #include "DrawCont.h"
  76. #endif
  77.  
  78. #ifndef PRINTHDL_H
  79. #include "PrintHdl.h"
  80. #endif
  81.  
  82. // ----- Framework Layer -----
  83.  
  84. #ifndef FWCONTXT_H
  85. #include "FWContxt.h"
  86. #endif
  87.  
  88. #ifndef FWUTIL_H
  89. #include "FWUtil.h"
  90. #endif
  91.  
  92. #ifndef FWPRESEN_H
  93. #include "FWPresen.h"
  94. #endif
  95.  
  96. #ifndef FWSCROLR_H
  97. #include "FWScrolr.h"
  98. #endif
  99.  
  100. #ifndef FWSCLBAR_H
  101. #include "FWSclBar.h"
  102. #endif
  103.  
  104. #ifndef FWGROWBX_H
  105. #include "FWGrowBx.h"
  106. #endif
  107.  
  108. #ifndef FWPRHDLR_H
  109. #include "FWPrHdlr.h"
  110. #endif
  111.  
  112. // ----- OS Layer -----
  113.  
  114. #ifndef FWMENU_H
  115. #include "FWMenu.h"
  116. #endif
  117.  
  118. #ifndef FWRGNSHP_H
  119. #include "FWRgnShp.h"
  120. #endif
  121.  
  122. #ifndef FWRECSHP_H
  123. #include "FWRecShp.h"
  124. #endif
  125.  
  126. #ifndef FWCURSOR_H
  127. #include "FWCursor.h"
  128. #endif
  129.  
  130. #ifndef FWEVENT_H
  131. #include "FWEvent.h"
  132. #endif
  133.  
  134. #ifndef FWODGEOM_H
  135. #include "FWODGeom.h"
  136. #endif
  137.  
  138. #ifndef FWLINSHP_H
  139. #include "FWLinShp.h"
  140. #endif
  141.  
  142. #ifndef FWBMPSHP_H
  143. #include "FWBmpShp.h"
  144. #endif
  145.  
  146. #ifndef FWFILEOP_H
  147. #include "FWFileOp.h"
  148. #endif
  149.  
  150. #ifndef FWEMBUTL_H
  151. #include "FWEmbUtl.h"
  152. #endif
  153.  
  154. // ----- OpenDoc Includes -----
  155.  
  156. #ifndef SOM_Module_OpenDoc_Commands_defined
  157. #include <CmdDefs.xh>
  158. #endif
  159.  
  160. #ifndef SOM_Module_OpenDoc_StdProps_defined
  161. #include <StdProps.xh>
  162. #endif
  163.  
  164. #ifndef SOM_ODSession_xh
  165. #include <ODSessn.xh>
  166. #endif
  167.  
  168. #ifndef SOM_ODDispatcher_xh
  169. #include <Disptch.xh>
  170. #endif
  171.  
  172. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  173. #include <StdTypes.xh>
  174. #endif
  175.  
  176. //========================================================================================
  177. // RunTime Info
  178. //========================================================================================
  179.  
  180. #ifdef FW_BUILD_MAC
  181. #pragma segment odfdrawframes
  182. #endif
  183.  
  184. FW_DEFINE_AUTO(CDrawFrame)
  185. FW_DEFINE_CLASS_M3(CDrawFrame, FW_CEmbeddingFrame, FW_MDraggableFrame, FW_MDroppableFrame)
  186.  
  187. //========================================================================================
  188. // CDrawFrame
  189. //========================================================================================
  190.  
  191. //----------------------------------------------------------------------------------------
  192. // CDrawFrame::CDrawFrame
  193. //----------------------------------------------------------------------------------------
  194.  
  195. CDrawFrame::CDrawFrame(Environment* ev, 
  196.                         ODFrame* odFrame,
  197.                         FW_CPresentation* presentation,
  198.                         CDrawPart* drawPart) :
  199.     FW_CEmbeddingFrame(ev, odFrame, presentation, drawPart),
  200.     FW_MDraggableFrame(ev, this),
  201.     FW_MDroppableFrame(ev, this),
  202.     fDrawPart(drawPart),
  203.     fSelection((CDrawSelection*)GetPresentation(ev)->GetSelection(ev)),
  204.     fHorzRuler(NULL),
  205.     fVertRuler(NULL),
  206.     fGridShown(TRUE),
  207.     fZoomFactor(FW_kFixedPos1)
  208. {    
  209.     fIsPrintingFrame = presentation == drawPart->GetPrintPresentation();
  210.     fRulersShown = !fIsPrintingFrame;
  211.     
  212.     FW_END_CONSTRUCTOR
  213. }
  214.  
  215. //----------------------------------------------------------------------------------------
  216. // CDrawFrame::~CDrawFrame
  217. //----------------------------------------------------------------------------------------
  218.  
  219. CDrawFrame::~CDrawFrame()
  220. {
  221.     FW_START_DESTRUCTOR
  222. }
  223.  
  224. //----------------------------------------------------------------------------------------
  225. //    CDrawFrame::DoAdjustMenus
  226. //----------------------------------------------------------------------------------------
  227.  
  228. FW_Handled CDrawFrame::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, FW_Boolean hasMenuFocus, FW_Boolean isRoot)
  229. {
  230. FW_UNUSED(isRoot);
  231.     // ----- Edit Menu -----
  232.     if (hasMenuFocus)
  233.     {
  234.         FW_Boolean canPaste = HasPropertyOnClipboard(ev, kODPropContents, NULL);  // we don't care about the type
  235.         menuBar->EnableCommand(ev, kODCommandPaste, canPaste); 
  236.         menuBar->EnableCommand(ev, kODCommandPasteAs, canPaste);
  237.         
  238.         menuBar->EnableCommand(ev, cDuplicate, !GetPart(ev)->IsReadOnly(ev) && !fSelection->IsEmpty(ev));
  239.         
  240.         menuBar->EnableAndToggleCommand(ev, cGraphicsGrid, TRUE, fGridShown);
  241.         menuBar->EnableAndToggleCommand(ev, cRulers, TRUE, fRulersShown);
  242.  
  243.         ODTypeToken defaultViewType = GetPresentation(ev)->GetDefaultEmbeddedFrameViewType(ev);
  244.         menuBar->EnableAndCheckCommand(ev, cAsFrame, TRUE, defaultViewType == FW_CPart::fgViewAsFrameToken);
  245.         menuBar->EnableAndCheckCommand(ev, cAsLargeIcon, TRUE, defaultViewType == FW_CPart::fgViewAsLargeIconToken);
  246.         menuBar->EnableAndCheckCommand(ev, cAsSmallIcon, TRUE, defaultViewType == FW_CPart::fgViewAsSmallIconToken);
  247.         menuBar->EnableAndCheckCommand(ev, cAsThumbnail, TRUE, defaultViewType == FW_CPart::fgViewAsThumbnailToken);
  248.  
  249.         menuBar->EnableAndCheckCommand(ev, cZoom50, TRUE, fZoomFactor == FW_DoubleToFixed(.5));
  250.         menuBar->EnableAndCheckCommand(ev, cZoom100, TRUE, fZoomFactor == FW_kFixedPos1);
  251.         menuBar->EnableAndCheckCommand(ev, cZoom200, TRUE, fZoomFactor == FW_IntToFixed(2));
  252.         
  253.          // for the menu we ignore the vPages value. It will be the same at least in this version.
  254.         unsigned char hPages, vPages;
  255.         fDrawPart->GetDocumentDimensions(ev, hPages, vPages);
  256.         menuBar->EnableAndCheckCommand(ev, cPages1x1, TRUE, hPages == 1);
  257.         menuBar->EnableAndCheckCommand(ev, cPages2x2, TRUE, hPages == 2);
  258.         menuBar->EnableAndCheckCommand(ev, cPages3x3, TRUE, hPages == 3);
  259.     }
  260.     
  261.     return FW_kNotHandled;
  262. }
  263.  
  264. //----------------------------------------------------------------------------------------
  265. //    CDrawFrame::AttachSourceFrame
  266. //----------------------------------------------------------------------------------------
  267.  
  268. void CDrawFrame::AttachSourceFrame(Environment* ev, FW_CFrame* sourceFrame)
  269. {
  270.     // call inherited first
  271.     FW_CEmbeddingFrame::AttachSourceFrame(ev, sourceFrame);
  272.     
  273.     // synchronize other non-content settings with the source frame
  274.     CDrawFrame *frame = FW_DYNAMIC_CAST(CDrawFrame, sourceFrame);
  275.  
  276.     // At this point, we don't have any views, so all we need to do is
  277.     // synchronize data members
  278.     
  279.     if(frame)
  280.     {
  281.         fZoomFactor = frame->GetZoomFactor();
  282.         fRulersShown = frame->AreRulersOn();
  283.         fGridShown = frame->IsGraphicsGridOn();
  284.     }
  285. }
  286.  
  287. //----------------------------------------------------------------------------------------
  288. //    CDrawFrame::ChangeDocPages
  289. //----------------------------------------------------------------------------------------
  290.  
  291. void CDrawFrame::ChangeDocPages(Environment* ev, short pages)
  292. {
  293. FW_UNUSED(pages);
  294.     unsigned char hOld, vOld;
  295.     fDrawPart->GetDocumentDimensions(ev, hOld, vOld);
  296.     if(hOld != pages || vOld != pages)
  297.     {
  298.         fDrawPart->SetDocumentDimensions(ev, pages, pages);
  299.         
  300.         FW_CPoint newSize = fDrawPart->GetPageSize();
  301.         
  302.         newSize.x = FW_MultipliedByInt(newSize.x, pages);
  303.         newSize.y = FW_MultipliedByInt(newSize.y, pages);
  304.         
  305.         fDrawPart->SetDrawingSize(ev, newSize);
  306.     }
  307. }
  308.  
  309. //----------------------------------------------------------------------------------------
  310. //    CDrawFrame::ChangeZoomFactor
  311. //----------------------------------------------------------------------------------------
  312.  
  313. void CDrawFrame::ChangeZoomFactor(Environment* ev, FW_Fixed zoomFactor)
  314. {
  315.     if(!IsPrintingFrame())
  316.     {
  317.         fHorzRuler->ZoomFactorChanged(ev, zoomFactor);
  318.         fVertRuler->ZoomFactorChanged(ev, zoomFactor);
  319.     }
  320.  
  321.     fZoomFactor = zoomFactor;
  322.  
  323.     AdjustContentViewSize(ev, FW_kDontRedraw);
  324.  
  325.     if(!IsPrintingFrame())
  326.     {
  327.         FW_ASSERT(GetScroller(ev));
  328.         GetScroller(ev)->ScaleBy(ev, FW_CPoint(zoomFactor, zoomFactor));    // Will invalidate
  329.     }
  330. }
  331.  
  332. //----------------------------------------------------------------------------------------
  333. //    CDrawFrame::DoMenu
  334. //----------------------------------------------------------------------------------------
  335.  
  336. FW_Handled CDrawFrame::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent)
  337. {
  338.     FW_Handled handled = FW_kHandled;
  339.     
  340.     ODCommandID commandID = theMenuEvent.GetCommandID(ev);
  341.     switch (commandID)
  342.     {
  343.         case cDuplicate:
  344.           {
  345.             CDuplicateCommand* cmd = FW_NEW(CDuplicateCommand, (ev, this));
  346.             cmd->Execute(ev);
  347.           }
  348.             break;
  349.  
  350.         case cGraphicsGrid:
  351.             fGridShown = !fGridShown;
  352.             GetContentView(ev)->Invalidate(ev);
  353.             break;
  354.         
  355.         case cRulers:
  356.             fRulersShown = !fRulersShown;
  357.             ToggleRulers(ev, fRulersShown, FW_kInvalidate);
  358.             break;
  359.         
  360.         case cZoom50:
  361.             if (fZoomFactor != FW_DoubleToFixed(0.5))
  362.                 ChangeZoomFactor(ev, FW_DoubleToFixed(0.5));
  363.             break;
  364.         case cZoom100:
  365.             if (fZoomFactor != FW_kFixedPos1)
  366.                 ChangeZoomFactor(ev, FW_kFixedPos1);
  367.             break;
  368.         case cZoom200:
  369.             if (fZoomFactor != FW_IntToFixed(2))
  370.                 ChangeZoomFactor(ev, FW_IntToFixed(2));
  371.             break;
  372.  
  373.         case cPages1x1:
  374.             ChangeDocPages(ev, 1);
  375.             break;
  376.             
  377.         case cPages2x2:
  378.             ChangeDocPages(ev, 2);
  379.             break;
  380.             
  381.         case cPages3x3:
  382.             ChangeDocPages(ev, 3);
  383.             break;
  384.     
  385.         case cAsFrame:
  386.             GetPresentation(ev)->SetDefaultEmbeddedFrameViewType(ev, FW_CPart::fgViewAsFrameToken);
  387.             break;
  388.         case cAsLargeIcon:
  389.             GetPresentation(ev)->SetDefaultEmbeddedFrameViewType(ev, FW_CPart::fgViewAsLargeIconToken);
  390.             break;
  391.         case cAsSmallIcon:
  392.             GetPresentation(ev)->SetDefaultEmbeddedFrameViewType(ev, FW_CPart::fgViewAsSmallIconToken);
  393.             break;
  394.         case cAsThumbnail:
  395.             GetPresentation(ev)->SetDefaultEmbeddedFrameViewType(ev, FW_CPart::fgViewAsThumbnailToken);
  396.             break;
  397.             
  398.         default:
  399.             handled = FW_kNotHandled;
  400.     }
  401.     
  402.     return handled;
  403. }
  404.  
  405. //----------------------------------------------------------------------------------------
  406. //    CDrawFrame::NewClipboardCommand
  407. //----------------------------------------------------------------------------------------
  408.  
  409. FW_CClipboardCommand* CDrawFrame::NewClipboardCommand(Environment* ev, ODCommandID commandID)
  410. {
  411.     return FW_NEW(CDrawClipboardCommand, (ev, commandID, fDrawPart, this, fSelection, FW_kCanUndo));
  412. }
  413.  
  414. //----------------------------------------------------------------------------------------
  415. //    CDrawFrame::NewInsertCommand
  416. //----------------------------------------------------------------------------------------
  417.  
  418. FW_CInsertCommand* CDrawFrame::NewInsertCommand(Environment* ev, const FW_PFileSpecification& fileSpec)
  419. {
  420.     return FW_NEW(CDrawInsertCommand, (ev, this, fileSpec, fSelection, FW_kCanUndo));
  421. }
  422.  
  423. //----------------------------------------------------------------------------------------
  424. //    CDrawFrame::CanAcceptDrop
  425. //----------------------------------------------------------------------------------------
  426. // As an embedding frame I can accept anything
  427.  
  428. ODDragResult CDrawFrame::CanAcceptDrop(Environment *ev, ODDragItemIterator* dragInfo)
  429. {
  430. FW_UNUSED(ev);
  431. FW_UNUSED(dragInfo);
  432.     return TRUE;
  433. }
  434.  
  435. //----------------------------------------------------------------------------------------
  436. //    CDrawFrame::DoActivateEvent
  437. //----------------------------------------------------------------------------------------
  438.  
  439. void CDrawFrame::DoActivateEvent(Environment* ev, const FW_CActivateEvent& theActivateEvent)
  440. {
  441. FW_UNUSED(theActivateEvent);
  442.     
  443.     if (HasSelectionFocus(ev))
  444.         fSelection->InvalidateSelectionHandles(ev, this);
  445. }
  446.  
  447. //----------------------------------------------------------------------------------------
  448. //    CDrawFrame::AdjustZoomedWindowSize
  449. //----------------------------------------------------------------------------------------
  450. //    Called when the window is zoomed
  451.  
  452. void CDrawFrame::AdjustZoomedWindowSize(Environment* ev, FW_CPoint& proposedSize)
  453. {
  454. FW_UNUSED(ev);
  455.     proposedSize = fDrawPart->GetDrawingSize();
  456.     proposedSize.x *= fZoomFactor;
  457.     proposedSize.y *= fZoomFactor;
  458.  
  459.     FW_CPoint sbSize = FW_CScrollBar::GetDefaultScrollBarSize();
  460.  
  461.     if (fRulersShown)
  462.     {
  463.         sbSize.x += kRulerWidth;
  464.         sbSize.y += kRulerWidth;
  465.     }
  466.     
  467.     proposedSize.x += sbSize.x + FW_IntToFixed(3);    // I want to leave a little space around
  468.     proposedSize.y += sbSize.y + FW_IntToFixed(3);
  469. }
  470.  
  471. //----------------------------------------------------------------------------------------
  472. //    CDrawFrame::AdjustWindowGrowLimits
  473. //----------------------------------------------------------------------------------------
  474. //    Called when the window is resized
  475.  
  476. void CDrawFrame::AdjustWindowGrowLimits(Environment* ev, FW_CPoint& minSize, FW_CPoint& maxSize)
  477. {
  478. FW_UNUSED(ev);
  479. FW_UNUSED(maxSize);
  480.     FW_CPoint sbSize = FW_CScrollBar::GetDefaultScrollBarSize();
  481.  
  482.     if (fRulersShown)
  483.     {
  484.         sbSize.x += kRulerWidth;
  485.         sbSize.y += kRulerWidth;
  486.     }
  487.     
  488.     minSize.x = FW_IntToFixed(72) + sbSize.x;
  489.     minSize.y = FW_IntToFixed(72) + sbSize.y;
  490. }
  491.  
  492. //----------------------------------------------------------------------------------------
  493. //    CDrawFrame::PostCreateViewFromStream
  494. //----------------------------------------------------------------------------------------
  495. // PostCreateViewFromStream is called after subviews are created from resources.  
  496. // Add code which cannot be handled by current resource types.
  497.  
  498. void CDrawFrame::PostCreateViewFromStream(Environment* ev)
  499. {    
  500.     if(!IsPrintingFrame())
  501.     {
  502.         fHorzRuler = (CRuler*) FindViewByID(ev, kHorzRulerID);
  503.         fVertRuler = (CRuler*) FindViewByID(ev, kVertRulerID);
  504.  
  505.         fHorzRuler->ZoomFactorChanged(ev, fZoomFactor);
  506.         fVertRuler->ZoomFactorChanged(ev, fZoomFactor);
  507.  
  508.         if (!fRulersShown)
  509.             ToggleRulers(ev, FALSE, FW_kDontRedraw);
  510.     }
  511.  
  512.     AdjustContentViewSize(ev, FW_kDontRedraw);
  513.         
  514.     // WARNING: Make sure that classes created from resources won't be dead-stripped
  515.     FW_DO_NOT_DEAD_STRIP(FW_CGrowBox);
  516.     FW_DO_NOT_DEAD_STRIP(FW_CScrollBarScroller);    
  517.     FW_DO_NOT_DEAD_STRIP(FW_CScrollBar);    
  518. }
  519.  
  520. //----------------------------------------------------------------------------------------
  521. // CDrawFrame::GetContentRect
  522. //----------------------------------------------------------------------------------------
  523.  
  524. FW_CRect CDrawFrame::GetContentRect(Environment* ev) const
  525. {
  526.     FW_CRect contentRect = GetBounds(ev);
  527.  
  528.     if (fRulersShown) 
  529.     {
  530.         // Make space for rulers
  531.         contentRect.top += kRulerWidth;
  532.         contentRect.left += kRulerWidth;
  533.     }
  534.     
  535.     if (IsRoot(ev) && ! fIsPrintingFrame)
  536.     {
  537.         FW_CPoint sbSize = FW_CScrollBar::GetDefaultScrollBarSize();
  538.     
  539.         contentRect.bottom -= sbSize.y;
  540.         contentRect.right -= sbSize.x;
  541.     }
  542.     
  543.     return contentRect;
  544. }
  545.  
  546. //----------------------------------------------------------------------------------------
  547. // CDrawFrame::AdjustContentViewSize
  548. //----------------------------------------------------------------------------------------
  549.  
  550. void CDrawFrame::AdjustContentViewSize(Environment* ev, FW_ERedrawVerb redraw)
  551. {
  552.     FW_CRect contentRect = GetContentRect(ev);    
  553.  
  554.     FW_CPoint drawingSize = fDrawPart->GetDrawingSize();
  555.         
  556.     // ----- I need to take into account the zoom factor -----
  557.     drawingSize.x *= fZoomFactor;
  558.     drawingSize.y *= fZoomFactor;
  559.  
  560.     FW_CPoint drawViewSize(FW_Minimum(drawingSize.x, contentRect.Width()),
  561.                             FW_Minimum(drawingSize.y, contentRect.Height()));
  562.  
  563.     FW_CPoint currentSize = GetContentView(ev)->GetSize(ev);
  564.     if (currentSize != drawViewSize)
  565.     {
  566.         if(!IsPrintingFrame())
  567.         {
  568.             fHorzRuler->SetSize(ev, FW_CPoint(drawViewSize.x, kRulerWidth), redraw);
  569.             fVertRuler->SetSize(ev, FW_CPoint(kRulerWidth, drawViewSize.y), redraw);            
  570.         }
  571.         
  572.         GetContentView(ev)->SetSize(ev, drawViewSize, redraw);
  573.     }
  574. }
  575.  
  576. //----------------------------------------------------------------------------------------
  577. //    CDrawFrame::NewDragCommand
  578. //----------------------------------------------------------------------------------------
  579.  
  580. FW_CDragCommand* CDrawFrame::NewDragCommand(Environment *ev, FW_CFrame* theFrame, const FW_CMouseEvent& theMouseEvent)
  581. {
  582. FW_UNUSED(theMouseEvent);
  583.     return FW_NEW(CDrawDragCommand, (ev, fDrawPart, theFrame,
  584.                                 fSelection,
  585.                                 FW_kCanUndo));
  586. }
  587.  
  588. //----------------------------------------------------------------------------------------
  589. //    CDrawFrame::NewDropCommand
  590. //----------------------------------------------------------------------------------------
  591.  
  592. FW_CDropCommand* CDrawFrame::NewDropCommand(Environment *ev,
  593.                                             FW_CFrame* frame,
  594.                                             ODDragItemIterator* dropInfo, 
  595.                                             ODFacet* facet, 
  596.                                             const FW_CPoint& dropPoint)
  597. {
  598.     return FW_NEW(CDrawDropCommand, (ev, fDrawPart, frame,
  599.                                     dropInfo, facet, dropPoint,
  600.                                     FW_kCanUndo));
  601. }
  602.  
  603. //----------------------------------------------------------------------------------------
  604. //    CDrawFrame::InvalidateShadowRect
  605. //----------------------------------------------------------------------------------------
  606.  
  607. void CDrawFrame::InvalidateShadowRect(Environment *ev)
  608. {
  609.     FW_CRect bounds = GetContentView(ev)->GetBounds(ev);
  610.     
  611.     // ----- I always remove the rulers so I am sure I will invalidate enough -----
  612.     bounds.left -= kRulerWidth;
  613.     bounds.top -= kRulerWidth;
  614.     
  615.     bounds.Inset(FW_kFixedNeg1, FW_kFixedNeg1);
  616.  
  617.     Invalidate(ev, bounds);
  618. }
  619.  
  620. //----------------------------------------------------------------------------------------
  621. //    CDrawFrame::ToggleRulers
  622. //----------------------------------------------------------------------------------------
  623.  
  624. void CDrawFrame::ToggleRulers(Environment *ev, FW_Boolean visible, FW_ERedrawVerb redraw)
  625. {
  626.     FW_ASSERT(fHorzRuler != NULL && fVertRuler != NULL);
  627.     fHorzRuler->SetVisible(ev, visible);
  628.     fVertRuler->SetVisible(ev, visible);
  629.     
  630.     FW_CRect frameRect = GetContentRect(ev);
  631.     
  632.     FW_CSuperView* contentView = GetContentView(ev);
  633.     
  634.     // I need to invalidate one more pixel for the black border
  635.     if (redraw == FW_kInvalidate)
  636.         InvalidateShadowRect(ev);
  637.  
  638.     GetContentView(ev)->SetLocation(ev, frameRect.TopLeft(), redraw);
  639.  
  640.     if (redraw == FW_kInvalidate)
  641.         InvalidateShadowRect(ev);
  642.     
  643.     AdjustContentViewSize(ev, redraw);
  644. }
  645.  
  646. //----------------------------------------------------------------------------------------
  647. //    CDrawFrame::Draw
  648. //----------------------------------------------------------------------------------------
  649.  
  650. void CDrawFrame::Draw(Environment *ev, ODFacet* odFacet, ODShape* invalidShape)
  651. {    
  652.     FW_CViewContext vc(ev, this, odFacet, invalidShape);
  653.  
  654.     FW_CSuperView* contentView = GetContentView(ev);
  655.     FW_CRect contentRect = GetContentRect(ev);
  656.     FW_CRect contentBounds = contentView->GetBounds(ev);
  657.         
  658.     // The only thing to draw is the top left corner box
  659.     if (fRulersShown)
  660.     {
  661.         FW_CRect box(FW_kFixedNeg1, FW_kFixedNeg1, kRulerWidth, kRulerWidth);
  662.         FW_CRectShape::RenderRect(vc, box, FW_kFill, FW_kWhiteEraseInk);
  663.         FW_CRectShape::RenderRect(vc, box, FW_kFrame, FW_kNormalInk, FW_CStyle(FW_kFixed0));
  664.         
  665.         contentRect.left -= kRulerWidth;
  666.         contentRect.top -= kRulerWidth;
  667.         
  668.         contentBounds.left -= kRulerWidth;
  669.         contentBounds.top -= kRulerWidth;
  670.     }
  671.  
  672.     if(odFacet->GetCanvas(ev)->IsDynamic(ev))
  673.     {    
  674.         FW_CAcquiredODShape shape1 = ::FW_NewODShape(ev, contentRect);
  675.         FW_CAcquiredODShape shape2 = ::FW_NewODShape(ev, contentBounds);
  676.         shape1->Subtract(ev, shape2);
  677.         if (!shape1->IsEmpty(ev))
  678.         {
  679.             FW_CRegionShape::RenderRegion(vc, shape1, FW_kFill, FW_kRGBLightGray);
  680.             
  681.             contentBounds.Inset(FW_kFixedNeg1, FW_kFixedNeg1);
  682.             FW_CRectShape::RenderRect(vc, contentBounds, FW_kFrame);
  683.         }
  684.     }
  685. }
  686.  
  687. //----------------------------------------------------------------------------------------
  688. //    CDrawFrame::NewPrintHandler
  689. //----------------------------------------------------------------------------------------
  690.  
  691. FW_CPrintHandler* CDrawFrame::NewPrintHandler(Environment* ev)
  692. {
  693.     if (GetPresentation(ev) == fDrawPart->GetMainPresentation())
  694.         return new CDrawPrintHandler(ev, this, fDrawPart->GetDrawContent(), fDrawPart->GetPrintPresentation());
  695.     else
  696.         return NULL;
  697. }
  698.  
  699. //----------------------------------------------------------------------------------------
  700. //    CDrawFrame::GetPrintResolution
  701. //----------------------------------------------------------------------------------------
  702.  
  703. void CDrawFrame::GetPrintResolution(Environment* ev, unsigned long& res)
  704. {
  705. FW_UNUSED(ev);
  706.  
  707.     res = 288;
  708. }
  709.  
  710.  
  711. //----------------------------------------------------------------------------------------
  712. //    CDrawFrame::FacetAdded
  713. //----------------------------------------------------------------------------------------
  714.  
  715. void CDrawFrame::FacetAdded(Environment* ev, ODFacet* facet, unsigned short facetCount)
  716. {
  717.     FW_CEmbeddingFrame::FacetAdded(ev, facet, facetCount);    // Call inherited
  718.  
  719.     // Perform "DoPostCreate"-type initialization here.
  720.     fDrawPart->DoPostCreate(ev);
  721.     
  722.     if(facetCount == 1)
  723.     {
  724.         // do this for the frame's first facet
  725.         unsigned char hPages, vPages;
  726.         fDrawPart->GetDocumentDimensions(ev, hPages, vPages);
  727.         
  728.         FW_CPoint newSize = fDrawPart->GetPageSize();
  729.         newSize.x = FW_MultipliedByInt(newSize.x, hPages);
  730.         newSize.y = FW_MultipliedByInt(newSize.y, vPages);
  731.         
  732.         fDrawPart->SetDrawingSize(ev, newSize);
  733.     }
  734. }
  735.  
  736. //----------------------------------------------------------------------------------------
  737. //    CDrawFrame::ExternalizeFrame
  738. //----------------------------------------------------------------------------------------
  739.  
  740. void CDrawFrame::ExternalizeFrame(Environment* ev, ODStorageUnitView* storageUnitView)
  741. {
  742.     FW_CEmbeddingFrame::ExternalizeFrame(ev, storageUnitView);
  743.     
  744.     FW_PStorageUnitSink suSink(ev, storageUnitView);
  745.     FW_CWritableStream stream(suSink);
  746.     
  747.     stream << fGridShown;
  748.     stream << fRulersShown;
  749.     stream << fZoomFactor;
  750. }
  751.  
  752. //----------------------------------------------------------------------------------------
  753. //    CDrawFrame::InternalizeFrame
  754. //----------------------------------------------------------------------------------------
  755.  
  756. void CDrawFrame::InternalizeFrame(Environment* ev, ODStorageUnitView* storageUnitView)
  757. {
  758.     FW_CEmbeddingFrame::InternalizeFrame(ev, storageUnitView);
  759.  
  760.     FW_PStorageUnitSink suSink(ev, storageUnitView);
  761.     FW_PBufferedSink sink(ev, suSink);
  762.     FW_CReadableStream stream(sink);
  763.     
  764.     stream >> fGridShown;
  765.     stream >> fRulersShown;
  766.     stream >> fZoomFactor;
  767. }
  768.  
  769. //----------------------------------------------------------------------------------------
  770. //    CDrawFrame::FocusStateChanged
  771. //----------------------------------------------------------------------------------------
  772.  
  773. void CDrawFrame::FocusStateChanged(Environment *ev, ODTypeToken focus, FW_Boolean newState, ODFrame* newOwner)
  774. {
  775.     FW_CEmbeddingFrame::FocusStateChanged(ev, focus, newState, newOwner);
  776.     
  777.     if (focus == FW_CPart::fgSelectionFocusToken)
  778.     {
  779.         //    If I am losing the selection focus for a frame other than one of mine then
  780.         //    set back the current tool to the selection tool
  781.         if (!this->IsSiblingFrameOf(ev, newOwner))
  782.             fDrawPart->SetTool(ev, kSelectTool);
  783.         
  784.         FW_CWindow* wind = GetWindow(ev);
  785.         if (wind && wind->IsActive(ev))
  786.             fSelection->InvalidateSelectionHandles(ev, this);
  787.     }
  788. }
  789.  
  790. //----------------------------------------------------------------------------------------
  791. //    CDrawFrame::IsInLinkDestination
  792. //----------------------------------------------------------------------------------------
  793.  
  794. FW_Boolean CDrawFrame::IsInLinkDestination(Environment* ev)
  795. {
  796.     return (this->GetODFrame(ev)->GetLinkStatus(ev) == kODInLinkDestination);
  797. }
  798.  
  799. //----------------------------------------------------------------------------------------
  800. //    CDrawFrame::EmbeddedFrameRequested
  801. //----------------------------------------------------------------------------------------
  802.  
  803. FW_MProxy* CDrawFrame::EmbeddedFrameRequested(Environment *ev,
  804.                                             FW_MProxy* baseProxy,
  805.                                             ODFrame* baseFrame,
  806.                                             ODShape* frameShape,
  807.                                             ODPart* embeddedPart,
  808.                                             ODTypeToken viewType,
  809.                                             ODTypeToken presentation,
  810.                                             ODID frameGroupID,
  811.                                             FW_Boolean isOverlaid,
  812.                                             FW_Boolean isSubFrame)
  813. {
  814. FW_UNUSED(baseFrame);
  815. FW_UNUSED(frameShape);
  816.     FW_CPresentation* myPresentation = GetPresentation(ev);
  817.     
  818.     CProxyShape* baseProxyShape = (CProxyShape*)baseProxy;
  819.     FW_CRect embeddedFrameBounds = baseProxyShape->GetFrameRect(ev);
  820.  
  821.     embeddedFrameBounds.Offset(embeddedFrameBounds.Width(), FW_kFixed0);
  822.     
  823.     CProxyShape* proxy = FW_NEW(CProxyShape, (ev, embeddedFrameBounds, fDrawPart));
  824.         
  825.     FW_CRect tempRect(embeddedFrameBounds);
  826.     tempRect.Place(FW_kFixed0, FW_kFixed0);
  827.     FW_CAcquiredODShape aqFrameShape = ::FW_NewODShape(ev, tempRect);
  828.     
  829.     FW_TRY
  830.     {
  831.          proxy->EmbedPart(ev, 
  832.                     myPresentation,
  833.                     embeddedPart,
  834.                     kODFrameObject,
  835.                     aqFrameShape,
  836.                     viewType,
  837.                     presentation,
  838.                     frameGroupID,
  839.                     isOverlaid,
  840.                     isSubFrame);
  841.     }
  842.     FW_CATCH_BEGIN
  843.     FW_CATCH_EVERYTHING () 
  844.     {
  845.         proxy->Release();
  846.         FW_THROW_SAME ();
  847.     }
  848.     FW_CATCH_END
  849.     
  850.     // ----- Now I can add it to my data                
  851.     fDrawPart->AddShapeToPart(ev, proxy);
  852.     
  853.     // AddShapeToPart acquired proxy. Since this function is actually returning
  854.     // an FW_MProxy, which is currently not refcounted, the caller (which is 
  855.     // happens to be a framework method) can't be counted on to release, so we
  856.     // have to do so for it.
  857.     
  858.     proxy->Release();
  859.     
  860.     // ----- Clip the facets -----
  861.     CDrawFacetClipper facetClipper(fDrawPart);
  862.     FW_CAcquiredODShape limitShape = ::FW_NewODShape(ev, embeddedFrameBounds);
  863.     facetClipper.Clip(ev, myPresentation, limitShape);
  864.     
  865.     return proxy;
  866. }
  867.  
  868. //----------------------------------------------------------------------------------------
  869. //    CDrawFrame::AdjustCursor
  870. //----------------------------------------------------------------------------------------
  871. // Rewrote AdjustCursor so we test for the case where the proxy is grouped
  872.  
  873. FW_Handled CDrawFrame::AdjustCursor(Environment *ev, ODFacet* facet, const FW_CPoint& theMousePoint, ODEventInfo* eventInfo)
  874. {
  875. FW_UNUSED(eventInfo);
  876.  
  877.     FW_Handled handled = FW_kNotHandled;
  878.     
  879.     ODFacet* embeddedFacet = GetFacetWithActiveBorderUnderMouse(ev, facet, theMousePoint);
  880.     if (embeddedFacet != NULL)
  881.     {
  882.         CProxyShape* proxy = FW_DYNAMIC_CAST(CProxyShape, fDrawPart->GetProxy(ev, embeddedFacet->GetFrame(ev)));
  883.         if (proxy->IsGrouped())
  884.             FW_gArrowCursor.Select();
  885.         else
  886.             FW_gOpenHandCursor.Select();
  887.             
  888.         handled = FW_kHandled;
  889.     }
  890.     
  891.     return handled;
  892. }
  893.  
  894. //----------------------------------------------------------------------------------------
  895. // CDrawFrame::DoMouseDownInEmbeddedFrameBorder
  896. //----------------------------------------------------------------------------------------
  897. //    Start Dragging an embedded frame using the active border
  898.  
  899. FW_Handled CDrawFrame::DoMouseDownInEmbeddedFrameBorder(Environment *ev, const FW_CBorderMouseEvent& theBorderMouseEvent)
  900. {    
  901.     ActivateFrame(ev, theBorderMouseEvent.GetFacet(ev));
  902.     
  903.     fDrawPart->SetTool(ev, kSelectTool);
  904.  
  905.     CProxyShape* proxy = FW_DYNAMIC_CAST(CProxyShape, fDrawPart->GetProxy(ev, theBorderMouseEvent.GetEmbeddedFacet(ev)->GetFrame(ev)));
  906.     if (!proxy->IsGrouped())
  907.     {
  908.         FW_gClosedHandCursor.Select();
  909.         Drag(ev, theBorderMouseEvent);
  910.     }
  911.     
  912.     return FW_kHandled;
  913. }
  914.  
  915. //----------------------------------------------------------------------------------------
  916. // CDrawFrame::DoMouseDownInEmbeddedFrame
  917. //----------------------------------------------------------------------------------------
  918. //    Test for double click in a embeddedFrame
  919.  
  920. FW_Handled CDrawFrame::DoMouseDownInEmbeddedFrame(Environment* ev, 
  921.                                                 const FW_CEmbeddedMouseEvent& theEmbeddedMouseEvent)
  922. {
  923.     FW_Handled handled = FW_kNotHandled;
  924.     
  925.     if (theEmbeddedMouseEvent.GetNumberOfClicks(ev) > 1)
  926.     {
  927.         ((FW_CEmbeddingFrame*)GetFrame(ev))->OpenSelection(ev);
  928.         handled = FW_kHandled;
  929.     }
  930.     
  931.     return handled;
  932. }
  933.  
  934.